//
//  VipTableViewCell.m
//  HQJFacilitator
//
//  Created by mymac on 2016/10/11.
//  Copyright © 2016年 Fujian first time iot technology investment co., LTD. All rights reserved.
//

#import "VipTableViewCell.h"

@implementation VipTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createUI];
            if (_isVipList == YES) {
                self.titleImageView.image = [UIImage imageNamed:@"member"];
            } else {
                self.titleImageView.image = [UIImage imageNamed:@"store"];
        
            }
    }
    
    
    
    return self;
}
-(UIImageView *)titleImageView {
    if (!_titleImageView) {
        _titleImageView = [[UIImageView alloc]init];
        _titleImageView.layer.cornerRadius = 20;
        _titleImageView.layer.masksToBounds = YES;
        [self addSubview:_titleImageView];
    }
    
    
    return _titleImageView;
}

-(UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
//        _nameLabel.backgroundColor = [UIColor blackColor];
        _nameLabel.textColor = [ManagerEngine getColor:@"323232"];
        _nameLabel.font = [UIFont systemFontOfSize:17 weight:.2];
        [self addSubview:_nameLabel];
    }
    
    
    return _nameLabel;
}
-(UILabel *)numerLabel {
    if (!_numerLabel) {
        _numerLabel = [[UILabel alloc]init];
//        _numerLabel.backgroundColor = [UIColor grayColor];
        _numerLabel.textColor = [ManagerEngine getColor:@"999999"];
        _numerLabel.font = [UIFont systemFontOfSize:15];
        [self addSubview:_numerLabel];
    }
    
    
    
    
    return _numerLabel;
}
-(UILabel *)ZHLabel {
    if (!_ZHLabel) {
        _ZHLabel = [[UILabel alloc]init];
//        _ZHLabel.backgroundColor = [ManagerEngine getColor:@"00ccb8"];
        _ZHLabel.textColor = [ManagerEngine getColor:@"00ccb8"];
        _ZHLabel.font = [UIFont systemFontOfSize:15 weight:.2];
        [self addSubview:_ZHLabel];
    }
    
    
    
    return _ZHLabel;
}
-(UILabel *)timerLabel {
    if (!_timerLabel) {
        _timerLabel = [[UILabel alloc]init];
//        _timerLabel.backgroundColor = [UIColor orangeColor];
        _timerLabel.textColor = [ManagerEngine getColor:@"999999"];
        _timerLabel.font = [UIFont systemFontOfSize:15];
        [self addSubview:_timerLabel];
    }
    
    
    return _timerLabel;
}
-(void)createUI {
    self.titleImageView.image = [UIImage imageNamed:@"store"];


    
}
-(void)updateLayout {
    [super updateLayout];
    
    
    self.titleImageView.sd_layout.leftSpaceToView(self,15).topSpaceToView(self,15).heightIs(40).widthIs(40);
    
    CGFloat nameSize = [ManagerEngine setTextWidthStr:self.nameLabel.text andFont:[UIFont systemFontOfSize:17 weight:.2]];
    
    CGFloat numeSize = [ManagerEngine setTextWidthStr:self.numerLabel.text andFont:[UIFont systemFontOfSize:15]];
    
    CGFloat ZHSize = [ManagerEngine setTextWidthStr:self.ZHLabel.text andFont:[UIFont systemFontOfSize:15 weight:.2]];
    
    CGFloat timerSize = [ManagerEngine setTextWidthStr:self.timerLabel.text andFont:[UIFont systemFontOfSize:15]];
    
    if (nameSize>WIDTH/2) {
         self.nameLabel.sd_layout.leftSpaceToView(self.titleImageView,5).topEqualToView(self.titleImageView).heightIs(20).widthIs(150);
    }else {
         self.nameLabel.sd_layout.leftSpaceToView(self.titleImageView,5).topEqualToView(self.titleImageView).heightIs(20).widthIs(nameSize);
    }
   
    
    self.numerLabel.sd_layout.leftEqualToView(self.nameLabel).topSpaceToView(self.nameLabel,0).heightIs(20).widthIs(numeSize);
    
    self.ZHLabel.sd_layout.leftSpaceToView(self,WIDTH-15-ZHSize).topEqualToView(self.nameLabel).heightIs(20).widthIs(ZHSize);
    
    self.timerLabel.sd_layout.leftSpaceToView(self,WIDTH-15-timerSize).topEqualToView(self.numerLabel).heightIs(20).widthIs(timerSize);
    
}

-(void)setModel:(VipModel *)model {
    
    _model = model;
    
    self.nameLabel.text = model.realname;
    
    self.numerLabel.text = model.mobile;
    
    self.ZHLabel.text = [NSString stringWithFormat:@"ZH:%@",model.ZH];
    
    self.timerLabel.text = model.addtime;
    
    
    
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
